<?php

namespace Yzadmin\Controller;
use Think\Controller;
class AdController extends CkController
{

   //系统设置首页 
   public function index()
   { 
 
     $data['cate']=M("ad")->order("sort asc,id asc")->select();
     $data['title']="广告管理";
     $this->assign($data);
     $this->display();
   }    
 
   
 

   //添加
   public function adds()
   {
     $data=I('post.');
     if(empty($data['title'])){
        $this->error("请输入广告标记");
     }
     if(empty($data['pic']) && empty($data['text']) &&empty($data['js'])){
        $this->error("请输入广告内容");
     }
     
        if(M("ad")->add($data)){
            $this->success("添加成功");
        }else{
            $this->error("添加失败");
        }
   }
  

  //删除
   public function del()
   {
     $id=(int)I('get.id');
     $data=M("ad")->where(array('id'=>$id))->delete();
     if($data!==false)
     {
        $this->success("删除成功!");
     }else
     {  
        $error=mysql_error();
        $this->error("删除失败!错误状态码:".$error);
     }
   }



   //修改
   public function update()
   {
     $id=(int)I('get.id');
     $data['ad']=M('ad')->find($id);
     $data['title']="分类修改";
     $this->assign($data);
     $this->display();
   }
   

   //修改处理
   public function updates()
   {
     $data=I("post.");
     $cate=D("ad");
     if(!$cate->create($data)){ 
        $this->error($cate->getError());
     }else{ 
        if($cate->where('id='.$data['id'])->save($data)!==false){
        $this->success("广告更新成功!");
        }else{
        $this->error("广告更新失败");
        }
     }
   }

  



   
}